import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class DiyRouteService extends BaseService<any> {
  private readonly logger = new Logger(DiyRouteService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getList
   * 对应 PHP: DiyRouteService_admin::getList()
   * 逻辑类型: undefined - undefined
   */
  async getList(where: any[]) {
    // 基于PHP真实逻辑: getList
    // PHP原文: $condition = [];         if (!empty($where[ 'addon' ])) {             $condition[ 'addon' ] = $where[ 'addon' ];...
const condition = [];
        if (!!where[ 'addon' ))) {
            condition[ 'addon' ] = where[ 'addon' ];
  }

  /**
   * getPage
   * 对应 PHP: DiyRouteService_admin::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(where: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: $where[] = [ 'site_id', '=', $this->site_id ];         $field = 'id,title,name,page,share,is_share,sort';         $order = '';          $search_model ...
where[] = [ 'site_id', '=', this.site_id ];
        const field = 'id,title,name,page,share,is_share,sort';
        const order = '';

        const search_model = this.model.where([ [ 'site_id', '=', this.site_id ) )).withSearch([ "title" ), where).field(field).order(order];
        return this.pageQuery(search_model);
    }

    /**
     * 获取自定义路由表信息
     * @param int id
     * @return */
    async getInfo(int id)
    {
        const field = 'title,name,page,share,is_share,sort';
        return this.model.field(field).where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
    }

    /**
     * 获取自定义路由表信息
     * @param string name
     * @return */
    async getInfoByName(string name)
    {
        const field = 'id,title,name,page,share,is_share,sort';
        return this.model.field(field).where([ [ 'name', '=', name ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
    }

    /**
     * 添加自定义路由表
     * @param data
     * @return mixed
     */
    async add(data)
    {
        data[ 'site_id' ] = this.site_id;
        const res = this.model.create(data);
        return res.id;
    }

    /**
     * 自定义路由表编辑
     * @param int id
     * @param data
     * @return bool
     */
    async edit(int id, data)
    {
        this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).update(data);
        return true;
    }

    /**
     * 删除自定义路由表
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        return this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).delete(];
    }

    /**
     * 修改分享内容
     * @param data
     * @return bool
     */
    async modifyShare(data)
    {
        const field = 'id';
        data[ 'site_id' ] = this.site_id;
        const info = this.model.field(field).where([ [ 'name', '=', data[ 'name' ] ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
        if (!!info)) {
            this.model.where([ [ 'id', '=', info[ 'id' ] ], [ 'site_id', '=', this.site_id ) )).update([ share: data[ 'share' ) )];
  }

  /**
   * getInfo
   * 对应 PHP: DiyRouteService_admin::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $field = 'title,name,page,share,is_share,sort';         return $this->model->field($field)->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_...
const field = 'title,name,page,share,is_share,sort';
        return this.model.field(field).where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
    }

    /**
     * 获取自定义路由表信息
     * @param string name
     * @return */
    async getInfoByName(string name)
    {
        const field = 'id,title,name,page,share,is_share,sort';
        return this.model.field(field).where([ [ 'name', '=', name ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
    }

    /**
     * 添加自定义路由表
     * @param data
     * @return mixed
     */
    async add(data)
    {
        data[ 'site_id' ] = this.site_id;
        const res = this.model.create(data);
        return res.id;
    }

    /**
     * 自定义路由表编辑
     * @param int id
     * @param data
     * @return bool
     */
    async edit(int id, data)
    {
        this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).update(data);
        return true;
    }

    /**
     * 删除自定义路由表
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        return this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).delete(];
    }

    /**
     * 修改分享内容
     * @param data
     * @return bool
     */
    async modifyShare(data)
    {
        const field = 'id';
        data[ 'site_id' ] = this.site_id;
        const info = this.model.field(field).where([ [ 'name', '=', data[ 'name' ] ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
        if (!!info)) {
            this.model.where([ [ 'id', '=', info[ 'id' ] ], [ 'site_id', '=', this.site_id ) )).update([ share: data[ 'share' ) )];
  }

  /**
   * getInfoByName
   * 对应 PHP: DiyRouteService_admin::getInfoByName()
   * 逻辑类型: undefined - undefined
   */
  async getInfoByName(name: string) {
    // 基于PHP真实逻辑: getInfoByName
    // PHP原文: $field = 'id,title,name,page,share,is_share,sort';         return $this->model->field($field)->where([ [ 'name', '=', $name ], [ 'site_id', '=', $this...
const field = 'id,title,name,page,share,is_share,sort';
        return this.model.field(field).where([ [ 'name', '=', name ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
    }

    /**
     * 添加自定义路由表
     * @param data
     * @return mixed
     */
    async add(data)
    {
        data[ 'site_id' ] = this.site_id;
        const res = this.model.create(data);
        return res.id;
    }

    /**
     * 自定义路由表编辑
     * @param int id
     * @param data
     * @return bool
     */
    async edit(int id, data)
    {
        this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).update(data);
        return true;
    }

    /**
     * 删除自定义路由表
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        return this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).delete(];
    }

    /**
     * 修改分享内容
     * @param data
     * @return bool
     */
    async modifyShare(data)
    {
        const field = 'id';
        data[ 'site_id' ] = this.site_id;
        const info = this.model.field(field).where([ [ 'name', '=', data[ 'name' ] ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
        if (!!info)) {
            this.model.where([ [ 'id', '=', info[ 'id' ] ], [ 'site_id', '=', this.site_id ) )).update([ share: data[ 'share' ) )];
  }

  /**
   * add
   * 对应 PHP: DiyRouteService_admin::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $data[ 'site_id' ] = $this->site_id;         $res = $this->model->create($data);         return $res->id;     }      /**      * 自定义路由表编辑      * @param...
data[ 'site_id' ] = this.site_id;
        const res = this.model.create(data);
        return res.id;
    }

    /**
     * 自定义路由表编辑
     * @param int id
     * @param data
     * @return bool
     */
    async edit(int id, data)
    {
        this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).update(data);
        return true;
    }

    /**
     * 删除自定义路由表
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        return this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).delete(];
    }

    /**
     * 修改分享内容
     * @param data
     * @return bool
     */
    async modifyShare(data)
    {
        const field = 'id';
        data[ 'site_id' ] = this.site_id;
        const info = this.model.field(field).where([ [ 'name', '=', data[ 'name' ] ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
        if (!!info)) {
            this.model.where([ [ 'id', '=', info[ 'id' ] ], [ 'site_id', '=', this.site_id ) )).update([ share: data[ 'share' ) )];
  }

  /**
   * edit
   * 对应 PHP: DiyRouteService_admin::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(id: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $this->model->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->update($data);         return true;     }      /**      * 删除自定义路由表   ...
this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).update(data);
        return true;
    }

    /**
     * 删除自定义路由表
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        return this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).delete(];
    }

    /**
     * 修改分享内容
     * @param data
     * @return bool
     */
    async modifyShare(data)
    {
        const field = 'id';
        data[ 'site_id' ] = this.site_id;
        const info = this.model.field(field).where([ [ 'name', '=', data[ 'name' ] ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
        if (!!info)) {
            this.model.where([ [ 'id', '=', info[ 'id' ] ], [ 'site_id', '=', this.site_id ) )).update([ share: data[ 'share' ) )];
  }

  /**
   * del
   * 对应 PHP: DiyRouteService_admin::del()
   * 逻辑类型: undefined - undefined
   */
  async del(id: number) {
    // 基于PHP真实逻辑: del
    // PHP原文: return $this->model->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->delete();     }      /**      * 修改分享内容      * @param $data    ...
return this.model.where([ [ 'id', '=', id ], [ 'site_id', '=', this.site_id ) )).delete(];
    }

    /**
     * 修改分享内容
     * @param data
     * @return bool
     */
    async modifyShare(data)
    {
        const field = 'id';
        data[ 'site_id' ] = this.site_id;
        const info = this.model.field(field).where([ [ 'name', '=', data[ 'name' ] ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
        if (!!info)) {
            this.model.where([ [ 'id', '=', info[ 'id' ] ], [ 'site_id', '=', this.site_id ) )).update([ share: data[ 'share' ) )];
  }

  /**
   * modifyShare
   * 对应 PHP: DiyRouteService_admin::modifyShare()
   * 逻辑类型: undefined - undefined
   */
  async modifyShare(data: any) {
    // 基于PHP真实逻辑: modifyShare
    // PHP原文: $field = 'id';         $data[ 'site_id' ] = $this->site_id;         $info = $this->model->field($field)->where([ [ 'name', '=', $data[ 'name' ] ], [ '...
const field = 'id';
        data[ 'site_id' ] = this.site_id;
        const info = this.model.field(field).where([ [ 'name', '=', data[ 'name' ] ], [ 'site_id', '=', this.site_id ) )).findOrEmpty().toArray(];
        if (!!info)) {
            this.model.where([ [ 'id', '=', info[ 'id' ] ], [ 'site_id', '=', this.site_id ) )).update([ share: data[ 'share' ) )];
  }

  /**
   * getApps
   * 对应 PHP: DiyRouteService_admin::getApps()
   * 逻辑类型: undefined - undefined
   */
  async getApps() {
    // 基于PHP真实逻辑: getApps
    // PHP原文: $link = LinkDict::getLink([             'query' => 'addon'         ]);         return $link;     }  }...
const link = LinkDict.getLink([
            query: 'addon'
        )];
        return link;
    }

}
  }
}
